import { defineStore } from "pinia"
import axios from "axios"

//使用defineStore创建一个小仓库
//定义state的类型
interface stateType{
    count: number,
    movieList: any[]
}
const useCountStore = defineStore("countStore", {
    state: ():stateType => {
        return {
            count: 0,
            movieList: []
        }
    },
    getters:{
        /* doubleCount():any{
            //getters里面this就是当前store对象
            console.log(this , 111);
            return this.count * 2
        } */

        doubleCount(state){
            // console.log(state , 111);
            return state.count * 2
        }
    },
    actions:{
        add(){ 
            this.count++
        },
        addN(n: number){
            this.count += n
        },
        addWait(){
            setTimeout(() => {
                this.count++
            }, 1000);
        },

        async getMovleList(){
            const result = await axios.get("https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a")
            this.movieList = result.data.data.list
        }
    }   
})

export default useCountStore